package com.zjj.lbw.microservice.sentinel.app.demo;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author zhanglei.zjj
 * @description Sentinel 熔断降级规则测试：慢调用比例、异常比例、异常数
 * @date 2023/7/29 16:18
 */
@RestController
public class CircuitBreakerTest {
    private AtomicInteger atomicInteger = new AtomicInteger();

    @RequestMapping("/breaker")
    public String test() {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "========test()========";
    }

    @RequestMapping("/breaker2")
    public String test2() {
        atomicInteger.getAndIncrement();
        if (atomicInteger.get() % 2 == 0){
            //模拟异常和异常比率
            int i = 1/0;
        }

        return "========test2()========";
    }
}
